<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<jsp:directive.page import="com.syzg.base.login.model.LoginObject" />

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/base/jsp/common/CommonEditTop.jsp"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>修改密码</title>
<link href="${ctx}/base/css/base.css" rel="stylesheet" type="text/css" />
<link href="${ctx}/base/css/common.css" rel="stylesheet" type="text/css" />
<link href="${ctx}/base/css/${customTheme}.css" rel="stylesheet"
	type="text/css" />
<script src="${ctx}/base/js/jquery/jquery.js" type="text/javascript"></script>
</head>

<body class="rightBody">
	<form method="post" action="" name="modifyPasswordForm">
		<div class="tableH2">
			<c:choose>
				<c:when test="${currentLogin.defaultPassword }">
					<font color="red">您正在使用默认密码进行登录，请修改密码后继续使用</font>
				</c:when>
				<c:otherwise>
				修改个人登录密码
			</c:otherwise>
			</c:choose>
		</div>
		<table class="list" align="center" width="600" border="0"
			cellspacing="0" cellpadding="0">
			<tr>
				<td class="tdBg" width="160">您的用户名为：</td>
				<td>${currentLogin.personName }</td>
			</tr>
			<c:if test="${!currentLogin.defaultPassword }">
				<tr>
					<td class="tdBg"><span class="fRed">*</span>请输入旧密码：</td>
					<td><input name="oldPassword" id="oldPassword" value=""
						type="password" /></td>
				</tr>
			</c:if>
			<tr>
				<td class="tdBg"><span class="fRed">*</span>请输入新密码：</td>
				<td><input name="password" id="password" value=""
					type="password" /></td>
			</tr>
			<tr>
				<td class="tdBg"><span class="fRed">*</span>请确认新密码：</td>
				<td><input name="confirmPassword" id="confirmPassword" value=""
					type="password" /></td>
			</tr>
		</table>
		<div class="tc mt30">
			<input type="button" value="确 定" class="btnB2"	onclick="updatePassword()" />&nbsp;&nbsp; 
			<!-- <input type="button" onclick="window.close();" value="取 消" class="btnB2" /> -->
		</div>
	</form>
	<script language="JavaScript">
		function updatePassword() {
			var defaultPassword = ${currentLogin.defaultPassword};
			if (!defaultPassword) {
				if ($("#oldPassword").val() == '') {
					alert("请输入旧密码！");
					$("#oldPassword").focus();
					return false;
				}
			}
			if ($("#password").val() == '') {
				alert("请输入新密码！");
				$("#password").focus();
				return false;
			} else {
				//验证密码复杂度
				var password = $("#password").val();
				if (password.length < 8) {
					alert("请输入至少八位密码！");
					$("#password").focus();
					return false;
				} else {
					var numStr = "0123456789", abcStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", sepStr = "~!@#$%^&*()_+.?:|";
					var containNum = false, containAbc = false, containSep = false;
					for (var i = 0; i < password.length; i++) {
						var c = password.charAt(i);
						//是否包含数字
						if (numStr.indexOf(c) >= 0) {
							containNum = true;
							continue;
						}
						//是否包含英文字母
						if (abcStr.indexOf(c) >= 0) {
							containAbc = true;
							continue;
						}
						//是否包含特殊字符
						if (sepStr.indexOf(c) >= 0) {
							containSep = true;
							continue;
						}
						//都包含则终止循环
						if (containNum && containAbc && containSep) {
							break;
						}
					}

					if (!containNum || !containAbc || !containSep) {
						alert("密码必须包含数字、字母、特殊字符！");
						$("#password").focus();
						return false
					}
				}
			}
			if ($("#confirmPassword").val() == '') {
				alert("请输入确认新密码！");
				$("#confirmPassword").focus();
				return false;
			}
			if ($("#password").val() != $("#confirmPassword").val()) {
				alert("新密码与确认新密码不一致，请重新输入！");
				return false;
			}

			$.ajax({
				url : "${ctx}/path/person/updatePassword",
				data : {
					"oldPassword" : $('#oldPassword').val(),
					"newPassword" : $("#password").val()
				},
				success : function(data) {
					if (data == 'success') {
						alert('密码已修改');
						parent.location.href = "${ctx}/logout";
					} else if (data == 'OLD_PASSWORD_ERROR'){
						alert('原密码错误');
					} else {
						alert('修改密码未成功');
					}
				}
			});
		}
	</script>
</body>
</html>
